// packageB/pages/package/smart_box/scan_login/scan_login.js
const mybehavior = require("../../../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/gm_user",

  },
  onClickLogin() {
    let url = this.data.baseUrl + "/set_smartg_token"
    let data = {
      key: this.data.scan_scene,
      name: this.data.name,
      token: this.data.token,

    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        wx.showModal({
            title: res.msg,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/home1/home1',
                });
              }
            }
          })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let name1 = wx.getStorageSync('name')
    let token1 = wx.getStorageSync('token')
    if (!name1) {
      wx.showModal({
        title: '请先登录!',
        showCancel: false,
        complete: (res) => {
          if (res.confirm) {
            wx.reLaunch({
              url: '/pages/login1/login',
            });
          }
        }
      })
    } else {
      const scene = decodeURIComponent(options.scene)
      console.log(scene);
      let self = this
      if (scene != "undefined") {
        self.setData({
          scan_scene: scene,
          token: token1,
          name: name1,

        })

      }
    }


    // self.getAllData()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})